package org.example.api.goods.goods.request;

import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.*;
import org.example.api.goods.goods.enums.GoodsStatusEnum;
import org.example.api.goods.goods.enums.GoodsTagEnum;
import org.example.api.goods.goods.enums.GoodsTypeEnum;
import org.example.api.goods.goods.enums.SalesTypeEnum;
import org.example.frw.api.base.common.LengthConstant;
import org.hibernate.validator.constraints.Length;

import java.util.List;
import java.util.Set;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
@EqualsAndHashCode
public class AddGoodsRequest {
    @Valid
    @NotNull
    private BaseInfoRequest baseInfo;
    @Valid
    @NotNull
    private PriceInfoRequest priceInfo;
    @Valid
    @NotNull
    private ParamInfoRequest paramsInfo;

    @Valid
    private DetailRequest detailInfo;

    @Getter
    @Setter
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @ToString
    @EqualsAndHashCode
    public static class DetailRequest{
        private String html;
    }

    @Getter
    @Setter
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @ToString
    @EqualsAndHashCode
    public static class ParamInfoRequest{
        private Set<GoodsTagEnum> tags;
        @Valid
        @NotEmpty
        private List<Param> params;


        @Getter
        @Setter
        @NoArgsConstructor
        @AllArgsConstructor
        @Builder
        @ToString
        @EqualsAndHashCode
        public static class Param{
            @NotBlank
            @Length(max = LengthConstant.TEXT)
            private String name;
            @NotBlank
            @Length(max = LengthConstant.TEXT)
            private String description;
        }
    }

    @Getter
    @Setter
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @ToString
    @EqualsAndHashCode
    public static class PriceInfoRequest{
        @NotEmpty
        private List<Sku> skus;
        @Builder.Default
        private SalesTypeEnum salesType = SalesTypeEnum.EXACT;
    }


    @Getter
    @Setter
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @ToString
    @EqualsAndHashCode
    public static class Sku{
        // 规格名称
        @NotBlank
        @NotNull
        @Length(max = LengthConstant.TEXT)
        private String name;
        // 规格值
        @NotBlank
        @NotNull
        @Length(max = LengthConstant.TEXT)
        private String description;
        // 规格图片
        @NotBlank
        @NotNull
        @Length(max = LengthConstant.MEDIUMTEXT)
        private String image;
        // 销售价格
        @NotNull
        @Min(value = 0)
        @NotNull
        @Max(value = Long.MAX_VALUE)
        private Long price;
        // 划线价格
        @NotNull
        @Min(value = 0)
        @Max(value = Long.MAX_VALUE)
        private Long linePrice;
        // 成本价格
        @NotNull
        @Min(value = 0)
        @Max(value = Long.MAX_VALUE)
        private Long costPrice;
        /**
         * 库存
         */
        @Builder.Default
        private Long stock = -1L;
        // 库存预警
        @Builder.Default
        private Boolean warnStock = false;
        // sku编码
        private String skuCode;
        // sku状态
        @Builder.Default
        private GoodsStatusEnum status = GoodsStatusEnum.ON_SHELVES;
    }


    @Getter
    @Setter
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @ToString
    @EqualsAndHashCode
    public static class BaseInfoRequest{
        /**
         * 实体商品还是虚拟商品
         */
        @Builder.Default
        private GoodsTypeEnum goodsType = GoodsTypeEnum.VIRTUAL_GOODS;
        /**
         * 标题
         */
        @NotBlank
        @NotNull
        @Length(max = LengthConstant.MEDIUMTEXT)
        private String title;
        /**
         * 附标题
         */
        @NotBlank
        @NotNull
        @Length(max = LengthConstant.MEDIUMTEXT)
        private String subTitle;
        /**
         * 商品主图
         */
        @NotBlank
        @NotNull
        @Length(max = LengthConstant.MEDIUMTEXT)
        private String mainImage;
        /**
         * 轮播图
         */
        @NotEmpty
        private List<String> carouselImage;
        /**
         * 商品分类
         */
        @NotBlank
        private String categoryId;

        /**
         * 商品状态
         */
        @Builder.Default
        private GoodsStatusEnum status = GoodsStatusEnum.ON_SHELVES;
    }
}
